package vn.edu.ptithcm.pim.dao;

import vn.edu.ptithcm.pim.dom.City;

import java.util.List;

import org.hibernate.LockMode;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


@SuppressWarnings("rawtypes")
public class CityDao extends HibernateDaoSupport {

	public void save(City city) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().save(city);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void saveOrUpdate(City city) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().saveOrUpdate(city);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void lock(City city) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().lock(city, LockMode.NONE);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void delete(City city) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().delete(city);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public City merge(City city) {
		try {
			return (City) getHibernateTemplate().merge(city);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public City findById(java.lang.Long id) {
		try {
			return (City) getHibernateTemplate().get(City.class, id);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List findByExample(City city) {
		try {
			return getHibernateTemplate().findByExample("City", city);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List getAll() {
		try {
			return getHibernateTemplate().loadAll(City.class);
		} catch (RuntimeException re) {
			throw re;
		}
	}
}
